package com.ruoyi.bom.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bom.domain.TqlMeasureUnit;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.bom.domain.TqlStapUnitTrans;
import com.ruoyi.bom.service.ITqlStapUnitTransService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物料单位换算Controller
 * 
 * @author ruoyi
 * @date 2023-12-31
 */
@RestController
@RequestMapping("/trans")
public class TqlStapUnitTransController extends BaseController
{
    @Autowired
    private ITqlStapUnitTransService tqlStapUnitTransService;

    /**
     * 查询物料单位换算列表
     */
    @RequiresPermissions("bom:trans:list")
    @GetMapping("/list")
    public TableDataInfo list(TqlStapUnitTrans tqlStapUnitTrans)
    {
        startPage();
        List<TqlStapUnitTrans> list = tqlStapUnitTransService.selectTqlStapUnitTransList(tqlStapUnitTrans);
        return getDataTable(list);
    }

    @GetMapping("/getMeasureUnit")
    public AjaxResult getMeasureUnit() {
        List<TqlMeasureUnit> list = tqlStapUnitTransService.getMeasureUnit();
        return success(list);
    }

    /**
     * 导出物料单位换算列表
     */
    @RequiresPermissions("bom:trans:export")
    @Log(title = "物料单位换算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TqlStapUnitTrans tqlStapUnitTrans)
    {
        List<TqlStapUnitTrans> list = tqlStapUnitTransService.selectTqlStapUnitTransList(tqlStapUnitTrans);
        ExcelUtil<TqlStapUnitTrans> util = new ExcelUtil<TqlStapUnitTrans>(TqlStapUnitTrans.class);
        util.exportExcel(response, list, "物料单位换算数据");
    }

    /**
     * 获取物料单位换算详细信息
     */
    @RequiresPermissions("bom:trans:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(tqlStapUnitTransService.selectTqlStapUnitTransById(id));
    }

    /**
     * 新增物料单位换算
     */
    @RequiresPermissions("bom:trans:add")
    @Log(title = "物料单位换算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TqlStapUnitTrans tqlStapUnitTrans)
    {
        TqlStapUnitTrans dto=new TqlStapUnitTrans();
        dto.setStapCode(tqlStapUnitTrans.getStapCode());
       List<TqlStapUnitTrans> list=tqlStapUnitTransService.selectTqlStapUnitTransList(dto);
       if(!CollectionUtils.isEmpty(list))return AjaxResult.error("物料已经存在");
        return toAjax(tqlStapUnitTransService.insertTqlStapUnitTrans(tqlStapUnitTrans));
    }

    /**
     * 修改物料单位换算
     */
    @RequiresPermissions("bom:trans:edit")
    @Log(title = "物料单位换算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TqlStapUnitTrans tqlStapUnitTrans)
    {
        return toAjax(tqlStapUnitTransService.updateTqlStapUnitTrans(tqlStapUnitTrans));
    }

    /**
     * 删除物料单位换算
     */
    @RequiresPermissions("bom:trans:remove")
    @Log(title = "物料单位换算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tqlStapUnitTransService.deleteTqlStapUnitTransByIds(ids));
    }
}
